#pragma once

#include "Util.h"
#include "Sntp.h"

#define  SNTP_FIRST_TIME (3*1000)

#ifdef _DEBUG 
#define  SNTP_NEXT_TIME  (15*1000)
#else
#define  SNTP_NEXT_TIME  (50*1000)
#endif

#define  SNTP_TIME_OUT   (5000)

extern  SYSTEMTIME g_stNowDate ;

BOOL IsSystemDate( SYSTEMTIME* lpTime );
int  RefreshNtpHost(void);

class CKtvSNTPClient 
{
public:
	CKtvSNTPClient( DWORD dwFirstGetTime = SNTP_FIRST_TIME,  DWORD dwNextGetTime = SNTP_NEXT_TIME, DWORD dwTimeOut = SNTP_TIME_OUT );
	~CKtvSNTPClient(void);

	int SendSntpMsg( LPCSTR pszHostName, int nPort  = 123 );	
	int RecvSntpMsg( NtpServerResponse& response );

	SYSTEMTIME* GetNetWorkTime(void);
	

protected:

	DWORD  m_dwNextGetTime;
	DWORD  m_dwTimeOut;

	bool   m_bWaiting;

	CNtpSocket m_ntpSocket ;

	int m_nUsingServer;

	DWORD m_dwSendTick;

	DWORD m_dwNextTimeToProc;

	SYSTEMTIME m_stNetWork;

public:

	int Update(void);
};
